<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <link rel="stylesheet" href="/lib/layui/css/layui.css" />
    <link rel="stylesheet" href="/css/public.css" />
    <script src="/lib/layui/layui.all.js"></script>
    <style>
      form {
        font-size: 14px;
      }
      .layui-input {
        width: 380px;
      }
    </style>
  </head>
  <body>
    <form class="layui-card layui-form" action="" lay-filter="usermsg">
      <div class="layui-card-header">修改用户信息</div>
      <div class="publicdiv">
        <div class="layui-form-item">
          <label class="layui-form-label">登录名称</label>
          <div class="layui-input-inline">
            <input
              type="text"
              name="username"
              required
              lay-verify="required|len"
              placeholder=""
              autocomplete="off"
              class="layui-input"
              disabled
            />
          </div>
        </div>
        <div class="layui-form-item">
          <label class="layui-form-label">用户昵称</label>
          <div class="layui-input-inline">
            <input
              type="text"
              name="nickname"
              required
              lay-verify="required"
              placeholder="请输入用户昵称"
              autocomplete="off"
              class="layui-input"
            />
          </div>
        </div>
        <div class="layui-form-item">
          <label class="layui-form-label">用户邮箱</label>
          <div class="layui-input-inline">
            <input
              type="text"
              name="email"
              required
              lay-verify="required"
              placeholder="请输入用户邮箱"
              autocomplete="off"
              class="layui-input"
            />
            <input
              type="hidden"
              name="id"
              required
              lay-verify="required"
              placeholder="请输入用户邮箱"
              autocomplete="off"
              class="layui-input"
            />
          </div>
        </div>
        <div class="layui-form-item">
          <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="formDemo">
              提交修改
            </button>
            <button class="layui-btn layui-btn-primary" id="btn">重置</button>
          </div>
        </div>
      </div>
    </form>
    <script src="/lib/jquery.js"></script>
    <script src="/js/setAjax.js"></script>
    <script>

      let form = layui.form;

      function apply() {
        $.ajax({
          url: "/my/userinfo",
          success: function (res) {
            if (res.status === 0) {
              form.val("usermsg", res.data);
            }
          },
        });
      }
      
      apply();

      $("#btn").on("click", function (e) {
        e.preventDefault();
        apply();
      });

      $("form").on("submit", function (e) {
        e.preventDefault();
        $.ajax({
          type: "post",
          url: "/my/userinfo",
          data: $("form").serialize(),
          success: function (res) {
            layer.msg(res.message);
            if (res.status === 0) {
              window.parent.getUserInfo();
            }
          },
        });
      });
    </script>
  </body>
</html>
